﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Axial.Tests
{
	[TestFixture]
	public class IfTests : TestBase
	{
		[Test]
		public void SimpleTest()
		{
			string check =
@"if (a > b)
	a = 3;";
			VerifyMethodOutput("Simple", check);
		}
		public void Simple()
		{
			int a = 2, b = 1;
			if (a > b)
				a = 3;
		}

		[Test]
		public void ElseTest()
		{
			string check =
@"if (a > b)
	a = 3;
else
	a = 4;";
			VerifyMethodOutput("Else", check);
		}
		public void Else()
		{
			int a = 2, b = 1;
			if (a > b)
				a = 3;
			else
				a = 4;
		}

		[Test]
		public void ConditionsTest()
		{
			string check =
@"if (a == b)
	a = 3;
if (a != b)
	a = 3;
if (a > b)
	a = 3;
if (a >= b)
	a = 3;
if (a <= b)
	a = 3;
if (a < b)
	a = 3;";
			VerifyMethodOutput("Conditions", check);
		}
		public void Conditions()
		{
			int a = 2, b = 1;
			if (a == b)
				a = 3;
			if (a != b)
				a = 3;
			if (a > b)
				a = 3;
			if (a >= b)
				a = 3;
			if (a <= b)
				a = 3;
			if (a < b)
				a = 3;
		}

		[Test]
		public void OrTest()
		{
			string check =
@"if (a == b || c == 4)
	a = 15;";
			VerifyMethodOutput("Or", check);
		}
		public void Or()
		{
			int a = 2, b = 1, c = 3;
			if (a == b || c == 4)
				a = 15;
		}

		[Test]
		public void OrAndTest()
		{
			string check =
@"if (a == b || c == 4 && a == c)
	a = 15;";
			VerifyMethodOutput("OrAnd", check);
		}
		public void OrAnd()
		{
			int a = 2, b = 1, c = 3;
			if (a == b || c == 4 && a == c)
				a = 15;
		}

		[Test]
		public void AndTest()
		{
			string check =
@"if (a == b && c == 4)
	a = 15;";
			VerifyMethodOutput("And", check);
		}
		public void And()
		{
			int a = 2, b = 1, c = 3;
			if (a == b && c == 4)
				a = 15;
		}

		[Test]
		public void AndOrTest()
		{
			string check =
@"if (a == b && c == 4 || a == c)
	a = 15;";
			VerifyMethodOutput("AndOr", check);
		}
		public void AndOr()
		{
			int a = 2, b = 1, c = 3;
			if (a == b && c == 4 || a == c)
				a = 15;
		}

		[Test]
		public void AndOrIfTest()
		{
			string check =
@"if (a == b && c == 4 || a == c)
	if (b == 2)
		a = 15;";
			VerifyMethodOutput("AndOrIf", check);
		}
		public void AndOrIf()
		{
			int a = 2, b = 1, c = 3;
			if (a == b && c == 4 || a == c)
				if (b == 2)
					a = 15;
		}

		[Test]
		public void AndOrIfAndTest()
		{
			string check =
@"if (a == b && c == 4 || a == c)
	if (b == 2 && c == 3)
		a = 15;";
			VerifyMethodOutput("AndOrIfAnd", check);
		}
		public void AndOrIfAnd()
		{
			int a = 2, b = 1, c = 3;
			if (a == b && c == 4 || a == c)
				if (b == 2 && c == 3)
					a = 15;
		}

		[Test]
        public void AndOrAndTest()
        {
            string check =
@"if (a == b && c == 4 || a == c && b == 2)
	a = 15;";
            VerifyMethodOutput("AndOrAnd", check);
        }
        public void AndOrAnd()
        {
            int a = 2, b = 1, c = 3;
            if (a == b && c == 4 || a == c && b == 2)
                a = 15;
        }

        [Test]
        public void AndAndIfTest()
        {
            string check =
@"if (a == b && c == 4 && a == c && b == 2)
	a = 15;";
            VerifyMethodOutput("AndAndIf", check);
        }
        public void AndAndIf()
        {
            int a = 2, b = 1, c = 3;
            if (a == b && c == 4 && a == c)
                if (b == 2)
                    a = 15;
        }

		[Test]
		public void AndIfAndTest()
		{
			string check =
@"if (a == b && c == 4 && b == 2 && a == c)
	a = 15;";
			VerifyMethodOutput("AndIfAnd", check);
		}
		public void AndIfAnd()
		{
			int a = 2, b = 1, c = 3;
			if (a == b && c == 4)
				if (b == 2 && a == c)
					a = 15;
		}

        [Test]
		public void OrAndIfTest()
		{
			string check =
@"if (a == b || c == 4 && a == c)
	if (b == 2)
		a = 15;";
			VerifyMethodOutput("OrAndIf", check);
		}
		public void OrAndIf()
		{
			int a = 2, b = 1, c = 3;
			if (a == b || c == 4 && a == c)
				if (b == 2)
					a = 15;
		}

		[Test]
		public void And3Test()
		{
			string check =
@"if (a == b && c == 4 && a == 2)
	a = 15;";
			VerifyMethodOutput("And3", check);
		}
		public void And3()
		{
			int a = 2, b = 1, c = 3;
			if (a == b && c == 4 && a == 2)
				a = 15;
		}

		[Test]
		public void Or3Test()
		{
			string check =
@"if (a == b || c == 4 || a == 2)
	a = 15;";
			VerifyMethodOutput("Or3", check);
		}
		public void Or3()
		{
			int a = 2, b = 1, c = 3;
			if (a == b || c == 4 || a == 2)
				a = 15;
		}

		[Test]
		public void VeryLongTest()
		{
			string check =
@"if (a == b && c != 4 && a > 2 && b < 3 && a >= c && c <= b && a == 3)
	a = 10;";
			VerifyMethodOutput("VeryLong", check);
		}
		public void VeryLong()
		{
			int a = 2, b = 1, c = 3;
			if (a == b && c != 4 && a > 2 && b < 3 && a >= c && c <= b && a == 3)
				a = 10;
		}

		[Test]
		public void VeryLongMixedTest()
		{
			string check =
@"if (a == b || c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)
	a = 10;";
			VerifyMethodOutput("VeryLongMixed", check);
		}
		public void VeryLongMixed()
		{
			int a = 2, b = 1, c = 3;
			if (a == b || c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)
				a = 10;
		}

        [Test]
        public void VeryLongMixedTest2()
        {
            string check =
@"if (a == b && c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)
	a = 10;";
            VerifyMethodOutput("VeryLongMixed2", check);
        }
        public void VeryLongMixed2()
        {
            int a = 2, b = 1, c = 3;
            if (a == b && c != 4 || a > 2 && b < 3 || a >= c && c <= b || a == 3)
                a = 10;
        }

        [Test]
        public void VeryLongMixedTest3()
        {
            string check =
@"if (a == b || c != 4 && a > 2 && b < 3 || a >= c && c <= b || a == 3)
	a = 10;";
            VerifyMethodOutput("VeryLongMixed3", check);
        }
        public void VeryLongMixed3()
        {
            int a = 2, b = 1, c = 3;
            if (a == b || c != 4 && a > 2 && b < 3 || a >= c && c <= b || a == 3)
                a = 10;
        }

        [Test]
		public void IfIfTest()
		{
			VerifyMethodOutput("IfIf", 
@"if (a == 1)
	a = 2;
if (b == 2)
	b = 1;");
		}
		public void IfIf()
		{
			int a = 0;
			int b = 1;
			if (a == 1)
				a = 2;
			if (b == 2)
				b = 1;
		}

		[Test]
		public void ElseIfTest()
		{
			VerifyMethodOutput("ElseIf",
@"if (a == 1)
	a = 2;
else
	a = 3;
if (b == 2)
	b = 1;");
		}
		public void ElseIf()
		{
			int a = 0;
			int b = 1;
			if (a == 1)
				a = 2;
			else
				a = 3;
			if (b == 2)
				b = 1;
		}

		[Test]
		public void OrElseIfTest()
		{
			VerifyMethodOutput("OrElseIf", @"
if (a == 1 || b == 2)
	a = 2;
else
	a = 3;
if (b == 3)
	b = 1;");
		}
		public void OrElseIf()
		{
			int a = 0;
			int b = 1;
			if (a == 1 || b == 2)
				a = 2;
			else
				a = 3;
			if (b == 3)
				b = 1;
		}

		[Test]
		public void AndElseIfTest()
		{
			VerifyMethodOutput("AndElseIf", @"
if (a == 1 && b == 2)
	a = 2;
else
	a = 3;
if (b == 3)
	b = 1;");
		}
		public void AndElseIf()
		{
			int a = 0;
			int b = 1;
			if (a == 1 && b == 2)
				a = 2;
			else
				a = 3;
			if (b == 3)
				b = 1;
		}

		[Test]
		public void ElseNestedIfElseTest()
		{
			VerifyMethodOutput("ElseNestedIfElse",
@"if (a == 1)
{
	if (b == 2)
		b = 3;
	else
		a = 3;
}
else
	a = 2;");
		}
		public void ElseNestedIfElse()
		{
			int a = 0;
			int b = 1;
			if (a == 1)
				if (b == 2)
					b = 3;
				else
					a = 3;
			else
				a = 2;
		}
	}
}
